<template>
    <IDrawer v-model="defaultValue" :loading="loading" :width="860" title="修改海关代码数据">
        <Form :model="data" :label-width="100" :rules="ruleValidate" ref="formCreate">
            <FormItem label="海关代码" prop="code">
                <Input v-model="data.code"></Input>
            </FormItem>
            <FormItem label="海关名称" prop="name">
                <Input v-model="data.name"></Input>
            </FormItem>
            <FormItem label="第一法定单位" prop="unit1">
                <RemoteSelect url="common/select/unit" v-model="data.unit1"></RemoteSelect>
            </FormItem>
            <FormItem label="第二法定单位" prop="unit2">
                <RemoteSelect url="common/select/unit" v-model="data.unit2"></RemoteSelect>
            </FormItem>
            <FormItem label="申报要素" prop="element">
                <Input v-model="data.element"></Input>
            </FormItem>
        </Form>
        <div slot="footer">
            <Button type="primary" icon="ios-add" @click="submit('formCreate')">提交</Button>
            <Button type="warning" icon="md-log-out" @click="defaultValue = false;">返回</Button>
        </div>
    </IDrawer>
</template>

<script>
    import IForm from "../../../../components/content/form";
    import contentDrawer from "../../../../mixins/contentDrawer";
    import IDrawer from "../../../../components/content/drawer";
    import IData from "./data";
    import RemoteSelect from "../../../../components/form/remoteSelect";

    export default {
        name: "update",
        mixins: [contentDrawer, IData],
        components: {RemoteSelect, IForm, IDrawer},
        data() {
            return {}
        },
        mounted(){
            this.getData();
        },
        methods: {
            getData(){
                this.loading = true;
                this.$http.get(`system/dictionary/hs_code/${this.props.id}/edit`, this.data).then((res) => {
                    this.data = res;
                }).finally(() => {
                    this.loading = false;
                });
            },
            submit(data) {
                this.validate(data).then(() => {
                    this.loading = true;
                    this.$http.put(`system/dictionary/hs_code/${this.props.id}`, this.data).then(() => {
                        this.defaultValue = false;
                    }).finally(() => {
                        this.loading = false;
                    });
                });
            }
        }
    }
</script>

<style scoped>

</style>
